package com.huan;

import org.apache.log4j.Logger;

import java.io.PrintWriter;
import java.net.BindException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Test5_talkServer {
    private static Logger logger = Logger.getLogger(Test3_TimeServer.class.getName());
    public static void main(String[] args) {
        ServerSocket ss = null;
        for (int i=10000;i<65535;i++){
            try {
                //完成一台时间服务器，选择空闲端口
                ss = new ServerSocket(i);
                break;
            }catch (Exception e){
                if (e instanceof BindException){
                    //用错误日志记录端口被占用的信息
                    logger.error("端口："+i+"已经被占用");
                }
            }
        }
        logger.info(ss.getInetAddress().getHostName()+"启动了，监听端口号："+ss.getLocalPort());

        //客户端通过键入聊天信息
        Scanner scanner = new Scanner(System.in);
        while (true){
//            try (
//                    Socket socket = ss.accept();
//                    //套接字流
//                    Scanner clienReader = new Scanner(socket.getInputStream());
//                    PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
//                    ){
//                logger.info("客户端"+socket.getRemoteSocketAddress()+"连接上来了");
//            }
        }
    }
}
